package cate.game.util.ct;

import cate.game.GameBody;
import cate.game.role.Role;
import cp.solution.business.sys.env.EnvironmentVarSets;

import java.util.HashMap;
import java.util.Map;

public class CT {

    public static int nPayDeliverCall;
    public static int nPayDeliverFail;

    public static String toDetail() {
        return "nPayDeliver(in=" +  nPayDeliverCall + ",fail=" + nPayDeliverFail+ ") envVer=" + EnvironmentVarSets.getInstance().getEnvVer();
    }

    private static Map<Integer, GsCT> gsMap = new HashMap<>();

    // 无需关注线程安全
    public static GsCT gs(int srvId) {
        try {
            GsCT g = gsMap.get(srvId);
            if(g == null) {
                g = new GsCT();
                g.srvId = srvId;
                gsMap.put(srvId, g);
            }
            return g;
        } catch (Exception e) {
            return new GsCT();
        }
    }

    public static GsCT gs(GameBody game) {
        if(game == null) {
            return new GsCT();
        }
        return gs(game.config.srvId);
    }

    public static GsCT gs(Role role) {
        if(role == null || role.getGame() == null) {
            return new GsCT();
        }
        return gs(role.getGame().config.srvId);
    }
}
